package de.baumann.browser.activitys.node

import android.content.Context
import android.content.Intent
import de.baumann.browser.R
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.IJoinNodeView
import de.baumann.browser.present.JoinNodePresenter
import de.baumann.browser.utils.Constants
import de.baumann.browser.utils.ViewUtil
import de.baumann.browser.utils.put
import kotlinx.android.synthetic.main.activity_join_node.*
import kotlinx.android.synthetic.main.include_tool_bar.*

/**
 *@author:
 *@date:2019/9/25 16:21
 *@discription: 加入节点
 */
@Deprecated("5.0.0版本之后活动结束，不再适用")
class JoinNodeActivity : BaseOdinActivity<IJoinNodeView, JoinNodePresenter>(), IJoinNodeView {

    companion object {
        fun startJoinNodeActivity(context: Context, nodeId: String) {
            context.startActivity(Intent(context, JoinNodeActivity::class.java).apply {
                putExtra("nodeId", nodeId)
            })
        }
    }

    override fun getTitleText(): String {
        return "加入节点"
    }

    override fun getLayout(): Int {
        return R.layout.activity_join_node
    }

    override fun initView() {
        initToolbar(commToolBar,commTitle)
        ViewUtil.configWebView(webviewJoin)
        webviewJoin.loadUrl(Constants.JOIN_ROLE_URL)

        btnJoin.setOnClickListener {
            if (!cbJoin.isChecked) {
                showShortToast("请阅读并同意加入规则")
                return@setOnClickListener
            }
            presenter.joinNode(getNodeId())
        }
    }

    override fun createPresenter(): JoinNodePresenter {
        return JoinNodePresenter()
    }

    override fun createView(): IJoinNodeView {
        return this
    }

    override fun initData() {
    }


    override fun getNodeId(): String {
        return intent.getStringExtra("nodeId")
    }

    override fun joinNodeSuccess() {
        put("isJoined", true)
        NodeStatusActivity.startNodeStatusActivity(mContext, getNodeId())
        finish()
    }

}
